#@head() 
#@header()
<title>客户列表</title>
#@aside("user")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<style>
	.box-body{padding:5px !important}
</style>
<div class="content-wrapper">
	<section class="content">
	<div class="nav-tabs-custom">
	#@usersmenu("rewards")
		
		<div class="tab-content">
		  <div class="tab-pane active" id="tab_1">
			<div class="box-body"> 

				<label style="float:left;margin-top:8px;margin-left:10px;">用户名：</label>
                <input id="usermobile" type="text" style="width:120px;float:left" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;margin-left:5px;">真实姓名：</label>
				<input type="text" id="realname" style="width:120px;float:left" class="form-control" placeholder="" >
				<label style="float:left;margin-top:8px;margin-left:5px;">领取时间：</label>
				<input id="startime" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="endtime" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
                 
				<label style="float:left;margin-top:8px;margin-left:5px;">奖励类型：</label>
				<select id="type" style="width:120px;float:left" class="form-control">
					<option value="">全部</option>
					<option value="jxq">加息券</option>
					<option value="tzhb">返现券</option>
					<option value="tyj">体验金</option> 
					<option value="xjhb">现金红包</option>
				</select>
				<label style="float:left;margin-top:8px;margin-left:5px;">使用状态：</label>
				<select id="status" style="width:120px;float:left" class="form-control">
					<option value="">全部</option>
					<option value="normal">未使用</option>
					<option value="used">已使用</option>
					<option value="expire">已过期</option>
				</select>
				<div class="col-xs-1">
				  <button id="seachuser" type="button" class="btn btn-info btn-flat">搜索</button>
				</div>

            </div>

			<div class="box-body">
				<table  id="example1" class="table table-striped">
					<thead>
						<tr>
							<th>用户名</th>
							<th>真实姓名</th>
							<th>名称</th>
							<th>类型</th>
							<th>发放额度</th> 
							<th>领取时间</th>
							<th>过期时间</th>
							<th>状态</th>
							<th>使用时间</th>
							<th>使用标的</th>
							<th>活动链接</th>
						</tr>
					</thead>
					<tbody id="userlist">
						
					</tbody>
				</table>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="userlist1"><a href="#">首页</a></li>
					<li id="userlist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
					<li id="userlist3"><a href="#">下一页</a></li>
					<li id="userlist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
			</div>
			</div>
		</div>
	</div>
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${mobile}</td>
		<td>${real_name}</td>
		<td>${coupon}</td>
		<td>${type}</td>
		<td>${amount}</td>
		<td>${create_time}</td>
		<td>${valid_end_time}</td>
		<td>${status}</td>
		<td>${apply_time}</td>
		<td>${trade}</td>
		<td>
			<button type="button" onclick="window.open('${link}')" class="btn btn-block btn-primary">打开</button>
		</td>

		
	</tr>
</script>
<script>
var totalPage = 1;
var pageNumber = 1;
var usermobile="";
var endtime = "";
var startime = "";
var type="";
var status = "";
var realname='';
 $(document).ready(function(){
	pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber,usermobile,endtime,startime,type,status,realname);
	$("#userlist5").html(pageNumber);
});
$("#userlist1").click(function(){
	$("#userlist").empty();
	pageNumber = 1;
	userlist(pageNumber,usermobile,endtime,startime,type,status,realname);
	$("#userlist5").html(pageNumber);
});
$("#userlist2").click(function(){
	if(pageNumber==1){
		alert("当前页是首页!");
	}else{
		$("#userlist").empty();
		pageNumber = pageNumber-1;
		userlist(pageNumber,usermobile,endtime,startime,type,status,realname);
		$("#userlist5").html(pageNumber);
	}
});
$("#userlist3").click(function(){
	if(pageNumber==totalPage){
		alert("当前页是尾页!");
	}else{
	$("#userlist").empty();
		pageNumber = pageNumber +1;
		userlist(pageNumber,usermobile,endtime,startime,type,status,realname);
		$("#userlist5").html(pageNumber);
	}
});
$("#userlist4").click(function(){
	$("#userlist").empty();
	pageNumber = totalPage;
	userlist(pageNumber,usermobile,endtime,startime,type,status,realname);
	$("#userlist5").html(pageNumber);
});
$("#seachuser").click(function(){
	$("#userlist").empty();
	pageNumber = 1;
	usermobile = $("#usermobile").val();
	endtime = $("#endtime").val();
	startime = $("#startime").val();
	type = $("#type").val();
	status = $("#status").val();
	realname = $("#realname").val();
	userlist(pageNumber,usermobile,endtime,startime,type,status,realname);
	$("#userlist5").html(pageNumber);
});

function userlist(pageNumber,usermobile,endtime,startime,type,status){
	var url = "#(path)/couponLog/list?token=#(session.token??)&mobile="+usermobile+"&page="+pageNumber+"&size=12&type="+type+"&createTimeStart="+startime+"&createTimeEnd="+endtime+"&status="+status+"&realName="+realname;
	$.getJSON(url, function(userli) {
		console.log(userli);
		totalPage = userli.data.page.totalPage;
		$("#userlist6").html(totalPage);
		$.each(userli.data.page.list, function(i, item){ 
			var youhui = "";
			if(!$.isBlank(item.tzhb)){
				youhui += "投资红包："+item.tzhb.amount+" 元 ";
			}
			if(!$.isBlank(item.tyj)){
				youhui += "体验金："+item.tyj.amount+" 元 ";
			}
			if(!$.isBlank(item.jxq)){
				youhui += "加息券："+item.jxq.amount +" % ";
			} 
			if(item.status=="used"){
				var status="已使用";
			}else if(item.status=="expire"){
				var status="已过期";
			}else if(item.status=="normal"){
				var status="未使用";
			}
			if(item.type=="jxq"){var type="加息券";amount=item.amount+"%";}
				else if(item.type=="tyj"){var type="体验金";amount=item.amount+" 元";}
				else if(item.type=="xjhb"){var type="现金红包";amount=item.amount+" 元";}
				else if(item.type=="tzhb"){var type="返现券";amount=item.amount+" 元";}
			if($.isBlank(item.trade)){var trade = "";}else{var trade = item.trade.bid_name}
			if($.isBlank(item.coupon)){var coupon = "现金奖励";}else{var coupon = item.coupon.name}
			var userlist = {status:status,valid_end_time:item.valid_end_time,link:item.link,trade:trade,apply_time:item.apply_time,create_time:item.create_time,coupon:coupon,amount:amount,name:item.name,type:type,summary:item.summary,mobile:item.mobile,real_name:item.real_name};
			$("#userlistall").tmpl(userlist).appendTo('#userlist');
		});
	});	
}


function GetRequest() {  
   var url = location.search; //获取url中"?"符后的字串  
   var theRequest = new Object();  
   if (url.indexOf("?") != -1) {  
      var str = url.substr(1);  
      strs = str.split("&");  
      for(var i = 0; i < strs.length; i ++) {  
         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
      }  
   }  
   return theRequest;  
}  
</script>
</body>
</html>